package com.dkm.dkmproject.service.impl;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.dkm.dkmproject.dao.UserTbMapper;
import com.dkm.dkmproject.domain.UserTb;
import com.dkm.dkmproject.service.IUserTbService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;


/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author 周佳佳
 * @since 2020-04-26
 */
@Service
public class UserTbServiceImpl extends ServiceImpl<UserTbMapper, UserTb> implements IUserTbService {
    @Resource
    UserTbMapper userTbMapper;
    @Override
    public int insertSelective(UserTb record) {
        return userTbMapper.insertSelective(record);
    }

    @Override
    public List<UserTb> selectUserId(Integer userId) {
        EntityWrapper<UserTb> entityWrapper=new EntityWrapper<>();
        entityWrapper.eq("user_id",userId);
        return userTbMapper.selectList(entityWrapper);
    }

    @Override
    public UserTb selectUser(String userName, String userPwd) {
        EntityWrapper<UserTb> queryWrapper=new EntityWrapper();
        queryWrapper.eq("wechat_name",userName);
        queryWrapper.eq("wechat_city",userPwd);
        queryWrapper.eq("user_state","2");
        List<UserTb> list=userTbMapper.selectList(queryWrapper);
        for (UserTb userTb : list) {
            if(!StringUtils.isEmpty(userName)){
                return userTb;
            }else{
                return null;
            }
        }
       return null;
    }

    @Override
    public int insertOne(UserTb userTb) {
        return userTbMapper.insert(userTb);
    }

    @Override
    public List<UserTb> selectPhone(String orPhoneOne, String orFwname) {
        EntityWrapper<UserTb> queryWrapper=new EntityWrapper();
        queryWrapper.eq("user_name",orFwname);
        queryWrapper.eq("user_state",1);
        queryWrapper.eq("user_phone",orPhoneOne);
        return userTbMapper.selectList(queryWrapper);
    }

    @Override
    public UserTb findById(String wechatWechatid) {
        return userTbMapper.findById(wechatWechatid);
    }
}
